package com.example.zyfypt_509sb.fragement;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.zyfypt_509sb.R;
import com.example.zyfypt_509sb.adapter.articleadapter;
import com.example.zyfypt_509sb.adapter.videoadater;
import com.example.zyfypt_509sb.bean.ArticleBean;
import com.example.zyfypt_509sb.bean.VideoBean;
import com.example.zyfypt_509sb.iface.Articlelistener;
import com.example.zyfypt_509sb.iface.videolistener;
import com.example.zyfypt_509sb.model.ArticleModer;
import com.example.zyfypt_509sb.model.videoModer;

import java.util.List;

/**
 * Created by 小博 on 2017/5/23.
 */

public class videofragement extends Fragment {

    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private videoadater myadapter;
    private List<VideoBean> list=null;
    private View view=null;
    private Context context;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        view=inflater.inflate(R.layout.videofragement,container,false);
        context=view.getContext();

        initRecyclerView();
        videoModer videoModer =new videoModer();
        videoModer.getResultList("video",2,"oeau24oa0naqqeglc0ec7j2bp0",videolistener);
        return view;
    }
   videolistener videolistener =new videolistener() {
        @Override
        public void onResponse(List<VideoBean> listbean) {

            list = listbean;
            myadapter.setList(list);

        }
        @Override
        public void onFail(String msg){
            Toast.makeText(context, "fail:" + msg, Toast.LENGTH_SHORT).show();
        }
    };

    private void initRecyclerView() {
        recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview1);

        //创建默认的线性LayoutManager
        layoutManager = new LinearLayoutManager(context);
        //设置布局
        recyclerView.setLayoutManager(layoutManager);
        //设置item的高度
        recyclerView.setHasFixedSize(true);
        //创建适配器
//        list=getData();
        myadapter= new videoadater(context);

        myadapter.setList(list);

        recyclerView.setAdapter(myadapter);

    }
}
